package com.formula.propertyshop.service;

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.ResourceHttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;

public class RestTemplateService {

	private RestTemplate restTemplate;
	private static RestTemplateService service;
	private ServiceConfigure serviceConfig;
	private RestTemplateService() {
		serviceConfig = new ServiceConfigure();
		restTemplate = new RestTemplate();
		// Add the Jackson message converter
		restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
		restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
		restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());  
		restTemplate.getMessageConverters().add(new ResourceHttpMessageConverter());

	}
	public static RestTemplateService getInstance(){
		if(service == null)
			service = new RestTemplateService();
		return service;
	}
	public  RestTemplate getRestTemplate(){
		return service.restTemplate;
	}
	public ServiceConfigure getServiceConfig() {
		return serviceConfig;
	}
	
}
